/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.spring.app.genpostagelabel;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;

/**
 *
 * @author ashwani
 * @desc Contain each buyer information
 */
public class BuyerDetail implements ColumnIndexes {

    private String userId;
    private String fullName;
    private String phoneNo;
    private String email;
    private String address1;
    private String address2;
    private String city;
    private String state;
    private String postcode;
    private String country;
    private String itemId;
    private String transactionId;
    private String itemTitle;
    private String quantity;
    private String salePrice;
    private String postage;
    private String totalPrice;
    private String saleDate;
    private String checkOutDate;
    private String paidDate;
    private String margin;
    //extra fields 
    private String itemCode;

    public void reset() {
        setUserId("");
        setFullName("");
        setPhoneNo("");
        setEmail("");
        setAddress1("");
        setAddress2("");
        setCity("");
        setState("");
        setPostcode("");
        setPostage("");
        setCountry("");
        setItemId("");
        setTransactionId("");
        setItemTitle("");
        setQuantity("");
        setSalePrice("");
        setTotalPrice("");
        setSaleDate("");
        setCheckOutDate("");
        setPaidDate("");
        setMargin("");


    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getPhoneNo() {
        return phoneNo;
    }

    public void setPhoneNo(String phoneNo) {
        this.phoneNo = phoneNo;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAddress1() {
        return address1;
    }

    public void setAddress1(String address1) {
        this.address1 = address1;
    }

    public String getAddress2() {
        return address2;
    }

    public void setAddress2(String address2) {
        this.address2 = address2;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getPostcode() {
        return postcode;
    }

    public void setPostcode(String postcode) {
        this.postcode = postcode;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getItemId() {
        return itemId;
    }

    public void setItemId(String itemId) {
        this.itemId = itemId;
    }

    public String getTransactionId() {
        return transactionId;
    }

    public void setTransactionId(String transactionId) {
        this.transactionId = transactionId;
    }

    public String getItemTitle() {
        return itemTitle;
    }

    public void setItemTitle(String itemTitle) {
        this.itemTitle = itemTitle;
    }

    public String getQuantity() {
        return quantity;
    }

    public void setQuantity(String quantity) {
        this.quantity = quantity;
    }

    public String getSalePrice() {
        return salePrice;
    }

    public void setSalePrice(String salePrice) {
        this.salePrice = salePrice;
    }

    public String getPostage() {
        return postage;
    }

    public void setPostage(String postage) {
        this.postage = postage;
    }

    public String getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(String totalPrice) {
        this.totalPrice = totalPrice;
    }

    public String getSaleDate() {
        return saleDate;
    }

    public void setSaleDate(String saleDate) {
        this.saleDate = saleDate;
    }

    public String getCheckOutDate() {
        return checkOutDate;
    }

    public void setCheckOutDate(String checkOutDate) {
        this.checkOutDate = checkOutDate;
    }

    public String getPaidDate() {
        return paidDate;
    }

    public void setPaidDate(String paidDate) {
        this.paidDate = paidDate;
    }

    public String getMargin() {
        return margin;
    }

    public void setMargin(String margin) {
        this.margin = margin;
    }

    public String getItemCode() {
        return itemCode;
    }

    public void setItemCode(String itemCode) {
        this.itemCode = itemCode;
    }

    public static String getStringValue(HSSFCell cell) {
        String value = "";
        try {


            if (cell != null) {
                int type = cell.getCellType();
                if (type == HSSFCell.CELL_TYPE_STRING) {
                    value = cell.getRichStringCellValue().toString();
                } else if (type == HSSFCell.CELL_TYPE_NUMERIC) {
                    double val = cell.getNumericCellValue();
                    long valLong = (long) Math.floor(val);
                    value = Long.toString(valLong);
                } else if (type == HSSFCell.CELL_TYPE_BOOLEAN) {
                    boolean val = cell.getBooleanCellValue();
                    value = Boolean.toString(val);
                } else if (type == HSSFCell.CELL_TYPE_BLANK) {
                    value = "";
                }
            } else {
                System.out.println("Error!! cell is null");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return value;
    }

    public boolean loadRow(HSSFRow row) {
        boolean retVal = false;
        HSSFCell cell = null;
        String cellValue = null;
        BuyerDetail value = new BuyerDetail();
        try {
            if (row != null) {
                //user id
                cell = row.getCell(COL_NO_USER_ID);
                if (cell != null) {
                    this.setUserId(getStringValue(cell));
                }

                //Full Name

                cell = row.getCell(COL_NO_FULLNAME);
                if (cell != null) {
                    this.setFullName(getStringValue(cell));
                }

                //Phone No
                cell = row.getCell(COL_NO_PHONE_NO);
                if (cell != null) {
                    this.setPhoneNo(getStringValue(cell));
                }

                //Email
                cell = row.getCell(COL_NO_EMAIL);
                if (cell != null) {
                    this.setEmail(getStringValue(cell));
                }

                //Address 1
                cell = row.getCell(COL_NO_ADDRESS_1);
                if (cell != null) {
                    this.setAddress1(getStringValue(cell));
                }

                //Address 2
                cell = row.getCell(COL_NO_ADDRESS_2);
                if (cell != null) {
                    this.setAddress2(getStringValue(cell));
                }

                //City
                cell = row.getCell(COL_NO_CITY);
                if (cell != null) {
                    this.setCity(getStringValue(cell));
                }

                //State
                cell = row.getCell(COL_NO_STATE);
                if (cell != null) {
                    this.setState(getStringValue(cell));
                }

                //Postcode
                cell = row.getCell(COL_NO_POSTCODE);
                if (cell != null) {
                    this.setPostcode(getStringValue(cell));
                }

                //Country
                cell = row.getCell(COL_NO_COUNTRY);
                if (cell != null) {
                    this.setCountry(getStringValue(cell));
                }

                //ITEM ID
                cell = row.getCell(COL_NO_ITEM_ID);
                if (cell != null) {
                    this.setItemId(getStringValue(cell));
                }

                //Transaction Id
                cell = row.getCell(COL_NO_TRANSACTION_ID);
                if (cell != null) {
                    this.setTransactionId(getStringValue(cell));
                }

                //Item Title
                cell = row.getCell(COL_NO_ITEM_TITLE);
                if (cell != null) {
                    this.setItemTitle(getStringValue(cell));
                }

                //Quantity
                cell = row.getCell(COL_NO_QUANTITY);
                if (cell != null) {
                    this.setQuantity(getStringValue(cell));
                }

                //Sale Price
                cell = row.getCell(COL_NO_SALE_PRICE);
                if (cell != null) {
                    this.setSalePrice(getStringValue(cell));
                }

                //Postage 
                cell = row.getCell(COL_NO_POSTAGE);
                if (cell != null) {
                    this.setPostage(getStringValue(cell));
                }

                //Total Price
                cell = row.getCell(COL_NO_TOTAL_PRICE);
                if (cell != null) {
                    this.setTotalPrice(getStringValue(cell));
                }

                //Sale Date
                cell = row.getCell(COL_NO_SALE_DATE);
                if (cell != null) {
                    this.setSaleDate(getStringValue(cell));
                }

                //Checkout Date
                cell = row.getCell(COL_NO_CHECKOUT_DATE);
                if (cell != null) {
                    this.setCheckOutDate(getStringValue(cell));
                }

                //Paid On Date
                cell = row.getCell(COL_NO_PAID_ON_DATE);
                if (cell != null) {
                    this.setPaidDate(getStringValue(cell));
                }
                retVal = true;

            }
        } catch (Exception e) {
            e.printStackTrace();
            retVal = false;
        }

        return retVal;
    }
}
